package factoryMode.factory.simpleFactory.order;

import factoryMode.factory.simpleFactory.pizza.Pizza;
import factoryMode.factory.simpleFactory.pizza.PizzaSimpleFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author： pang-yun
 * @date： 2021-10-21 13:56
 * 功能目的 ：用于  订购披萨
 */
public class PizzaOrder {

    // 构造器
/*    public PizzaOrder() {
        Pizza pizza = null;
        String orderType ;
        do {
            orderType=getType();
            if (orderType.equals("cheese")) {
                pizza = new CheesePizza();
                pizza.setName("cheese");
            } else if (orderType.equals("Greek")) {
                pizza = new GreekPizza();
                pizza.setName("Greek ");
            } else {
                break;
            }
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }*/

    // pizzaOrder 构造器
    public PizzaOrder(PizzaSimpleFactory simpleFactory) {
        setFactory(simpleFactory);
    }

    // 静态的构造
    public PizzaOrder() {
        staticFactory();
    }

    // 静态工厂
    public void staticFactory() {
        String orderType = "";
        do {
            orderType = getType();
            PizzaSimpleFactory.staticCreate(orderType);

        } while (true);
    }


    //-------------------------------------------------------------
    // 定义一个简单 工厂对象
    PizzaSimpleFactory simpleFactory;
    Pizza pizza = null;

    public void setFactory(PizzaSimpleFactory simpleFactory) {
        String orderType = "";
        this.simpleFactory = simpleFactory; // 设置简单工厂对象
        do {
            orderType = getType();
            this.simpleFactory.createPizza(orderType);

        } while (true);
    }


    //从控制台 获取想订购pizza 的种类
    private String getType() {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入pizza种类:");
            String s = reader.readLine();
            return s;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
